package cn.xzc.job.pojo;

import java.io.File;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.jar.JarFile;

/**
 * @author 熊志聪
 * @Classname PackageScanParam
 * @Description package扫描时需要的参数
 * @Date 2024/1/29 18:59
 */
public class PackageScanParam {
    /**
     * Captcha.class.getPackage().getName()
     * 包对应的名,允许为空
     */
    private String packageName;
    /**
     * 类的过滤条件
     * 函数式接口：断言
     */
    private Predicate<Class<?>> classPredicate;
    /**
     * method的过滤条件
     * 函数式接口：断言
     */
    private Predicate<Method> methodPredicate;
    /**
     * 存储符合条件的集合
     */
    private Set<AnnotatedElement> res;

    /**
     * 当前文件
     */
    private File file;
    /**
     * 当前的jar包文件
     */
    private JarFile jar;
    private String curDirPath;

    /**
     * 加载className时，
     * packageName为空或者scanJavaClassPaths方法时，initialize=false
     * 当要扫描全部的类时，加载类过程中不需要进行类初始化加载静态块
     * Class.forName(className, initialize, loader)
     */
    private boolean initialize;

    public PackageScanParam copy() {
        PackageScanParam scanParam = new PackageScanParam();
        scanParam.setPackageName(getPackageName());
        scanParam.setClassPredicate(getClassPredicate());
        scanParam.setMethodPredicate(getMethodPredicate());
        scanParam.setRes(getRes());
        scanParam.setInitialize(isInitialize());
        return scanParam;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public Predicate<Class<?>> getClassPredicate() {
        return classPredicate;
    }

    public void setClassPredicate(Predicate<Class<?>> classPredicate) {
        this.classPredicate = classPredicate;
    }

    public Predicate<Method> getMethodPredicate() {
        return methodPredicate;
    }

    public void setMethodPredicate(Predicate<Method> methodPredicate) {
        this.methodPredicate = methodPredicate;
    }

    public Set<AnnotatedElement> getRes() {
        return res;
    }

    public void setRes(Set<AnnotatedElement> res) {
        this.res = res;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public JarFile getJar() {
        return jar;
    }

    public void setJar(JarFile jar) {
        this.jar = jar;
    }

    public String getCurDirPath() {
        return curDirPath;
    }

    public void setCurDirPath(String curDirPath) {
        this.curDirPath = curDirPath;
    }

    public boolean isInitialize() {
        return initialize;
    }

    public void setInitialize(boolean initialize) {
        this.initialize = initialize;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof PackageScanParam)) {
            return false;
        }
        PackageScanParam that = (PackageScanParam) o;
        return initialize == that.initialize && Objects.equals(packageName, that.packageName) && Objects.equals(classPredicate, that.classPredicate) && Objects.equals(methodPredicate, that.methodPredicate) && Objects.equals(res, that.res) && Objects.equals(file, that.file) && Objects.equals(jar, that.jar) && Objects.equals(curDirPath, that.curDirPath);
    }

    @Override
    public int hashCode() {
        return Objects.hash(packageName, classPredicate, methodPredicate, res, file, jar, curDirPath, initialize);
    }
}
